package com.ml.mall.api.tax;

import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.tax.TaxAddDto;
import com.ml.mall.bean.req.tax.TaxDelDto;
import com.ml.mall.bean.req.tax.TaxQueryPageDto;
import com.ml.mall.bean.req.tax.TaxUpdDto;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.entity.tax.Tax;
import com.ml.mall.service.tax.TaxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/tax")
@Api(tags = "【auth】税率信息相关接口")
public class TaxController {
    @Autowired
    private TaxService taxService;

    @PostMapping("/new")
    @ApiOperation(value = "税率信息添加")
//  @RequiresPermissions(PermissionConst.TAX_NEW)
    public ApiRestResult addTax(@RequestBody @Valid TaxAddDto dto){
        int i = taxService.addTax(dto);
        if (i==0){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok();
    }

    @PostMapping("/edit")
    @ApiOperation(value = "税率信息更新")
//  @RequiresPermissions(PermissionConst.TAX_EDIT)
    public ApiRestResult updTax(@RequestBody @Valid TaxUpdDto dto){
        int i = taxService.updTax(dto);
        if (i==0){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok();
    }

    @PostMapping("/query_page")
    @ApiOperation(value = "税率信息分页查询")
//  @RequiresPermissions(PermissionConst.TAX_QUERY_PAGE)
    public ApiRestResult queryPageTax(@RequestBody TaxQueryPageDto dto){
        com.ml.mall.bean.page.Page<Tax> taxPageRes =taxService.queryByPage(dto);
        if (taxPageRes ==null){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok(taxPageRes);
    }

//    @PostMapping("/del") // 暂不提供删除
//    @ApiOperation(value = "税率信息批量删除")
//    public ApiRestResult delTax(@RequestBody TaxDelDto dto){
//        int i = taxService.delTax(dto);
//        if (i==0){
//            return ApiRestResult.err();
//        }
//        return ApiRestResult.ok();
//    }
}
